var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp();
var page = 1;
var loadingMore = false;
var hasMore = true;

Page({

   data: {

     uid:0,
     token: '',
     waithao: 0, 
     colorSet: '',

   },
   /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    hasMore = true;
    page = 1;
    this.getLoginUserInfo();
    this.getWaithao();
    var tc = app.get_tc();
    
    //获取颜色配置
    app.getColorSetData(function (color) {
      that.setData({
        colorSet: color
      })
    });
  },

  getLoginUserInfo: function(inviteuid){
    var that = this;
    //调用应用实例的方法获取全局数据
    app.LoginUserInfo(function (res) {
      if (res && res != -1) {
        //更新数据
        that.setData({
          tc: app.get_tc(),
          uid: res.uid,
          token: res.token
        })
      } else {
        app.reAuthorize(reGetUserInfo);
      }
    }, inviteuid);
  },
  
  //查询领号等待数
  getWaithao:function(){
    var that = this;
    //查询领号等待数
    var privatekey = utilMd5.hexMD5(that.data.uid + 'waithao2' + that.data.token);
    
     util.api({
      method: "post",
      data: {
        ac: "waithao2",
        uid: that.data.uid,
        binduid: util.orgid, 
        privatekey: privatekey
      },
      
      success: function (responseData) {
        console.log("调试--查询领号等待数接口:", responseData.data);
        that.setData({
          waithao: responseData.data,
        });
        
      }
    });
  },

   getXiaohao:function(e){
     wx.showLoading({
      title: '加载中',
      mask: true,
    })
     var that = this;
     var testId = e.currentTarget.dataset.testid;
     //销号接口
    var privatekey4 = utilMd5.hexMD5(that.data.uid + 'xiaohao' + that.data.token);
     util.api({
      method: "post",
      data: {
        ac: "xiaohao",
        uid: that.data.uid,
        orgid: util.orgid, 
        cid: testId,
        privatekey: privatekey4
      },
      
      success: function (responseData) {
        that.getWaithao();
        wx.hideLoading();
      }
    });


  },
})